Skip to content

add top_hit metric#7302

Merged
ppisljar merged 46 commits intoelastic:masterfrom
scampi:latest-value
Jan 4, 2017
Merged

add top_hit metric#7302
ppisljar merged 46 commits intoelastic:masterfrom
scampi:latest-value

Conversation

@scampi
Copy link
Copy Markdown
Contributor

@scampi scampi commented May 26, 2016

close #6877

Display the first/last value of a field, for a set of documents sorted on some field (e.g., a date).

TODO

  • aggregation of multivalued field
  • object in array use case
  • use AggConfigResult.toString for displaying arrays in the metric vis

Test

Index

Create the weather index with the following mapping:

$ curl -XPUT 'http://localhost:9200/weather' -d '
{
   "mappings": {
      "Weather": {
         "properties": {
            "timestamp": {
               "type": "date",
               "format": "date_optional_time"
            },
            "location": {
               "index": "not_analyzed",
               "type": "string"
            }
         }
      }
   }
}
'

Data

Add a document at a time.

$ curl -XPOST 'http://localhost:9200/weather/Weather/' -d '
{
  "location": "France",
  "temperature": 28,
  "timestamp": "2016-05-26T21:22:18+01:00"
}
'
$ curl -XPOST 'http://localhost:9200/weather/Weather/' -d '
{
  "location": "France",
  "temperature": 23.5,
  "timestamp": "2016-05-26T22:59:04+01:00"
}
'

Visualization

We can see what is the latest recorded temperature in France by doing the following:

Create either a vertical bar or a data table:

  • add a Latest metric:
    • "Field": the field which value to display, here temperature
    • "Sort On": the field to sort the data on, here timestamp
  • add a terms bucket on the field location.

@ghost
Copy link
Copy Markdown

ghost commented May 26, 2016

Jenkins standing by to test this. If you aren't a maintainer, you can ignore this comment. Someone with commit access, please review this and clear it for Jenkins to run; then say 'jenkins, test it'.

@scampi scampi changed the title add top_hits aggregation add top_hits metric May 26, 2016
@panda01 panda01 self-assigned this Jun 9, 2016
@panda01
Copy link
Copy Markdown
Contributor

panda01 commented Jun 9, 2016

Jenkins, test it.

@scampi
Copy link
Copy Markdown
Contributor Author

scampi commented Jun 9, 2016

In the jenkins logs, it fails with the exception java.lang.IllegalArgumentException: unknown setting [es.path.conf] did you mean [path.conf]?. Do you know what that is ?

@scampi
Copy link
Copy Markdown
Contributor Author

scampi commented Jun 9, 2016

With this fix elastic/libesvm@e3fd2ca I am able to run tests on my machine. Thanks @spalger for the fix ;o)

@spalger
Copy link
Copy Markdown
Contributor

spalger commented Jun 9, 2016

jenkins, test it

@scampi
Copy link
Copy Markdown
Contributor Author

scampi commented Jun 10, 2016

jenkins, test it

@panda01
Copy link
Copy Markdown
Contributor

panda01 commented Jun 10, 2016

Only, we (elastic members) can trigger the tests.

@panda01
Copy link
Copy Markdown
Contributor

panda01 commented Jun 10, 2016

Jenkins, test it.

@panda01
Copy link
Copy Markdown
Contributor

panda01 commented Jun 10, 2016

So it seems that this doesn't work with nested fields, through (I believe) no fault of your own, I'm not really sure where to go to fix this either.
no-nested

@panda01
Copy link
Copy Markdown
Contributor

panda01 commented Jun 10, 2016

Some other images that helped me reach this conclusion.

screen shot 2016-06-10 at 2 26 51 pm
screen shot 2016-06-10 at 2 27 07 pm

@panda01
Copy link
Copy Markdown
Contributor

panda01 commented Jun 10, 2016

Also, I'm not a fan this implementation, it is IMO is a bit limiting. I feel like the top_hits agg has other uses and by you only limiting it to order: desc it becomes a latest.

I say we take this away and leave it as kind of a top_hits agg. As an extra we can add if you want to do latest here is how you do it.

@panda01
Copy link
Copy Markdown
Contributor

panda01 commented Jun 10, 2016

Hmm, also I don't think these tests are something you caused. By the time you come back around they should be good to go though.

@scampi
Copy link
Copy Markdown
Contributor Author

scampi commented Jun 11, 2016

Thanks for spotting the problem with nested fields.

As an extra we can add if you want to do latest here is how you do it.

I think there is something missing to your comment, since I don't understand that sentence as it is now.

@epixa epixa removed the P2 label Jun 13, 2016
@panda01
Copy link
Copy Markdown
Contributor

panda01 commented Jun 13, 2016

@scampi Nope, I just worded that poorly. What I mean to say is after you add this metric, and remove the limitation on order, you can add steps that people can follow in order to get the latest value.

@scampi
Copy link
Copy Markdown
Contributor Author

scampi commented Jun 14, 2016

@panda01 Sorry I am still confused...

Do you want me to provide a combobox with, e.g., two options (desc and asc), so that the order option is not hardcoded ?

Otherwise, can you clarify what those steps are ? For the issue #6877 I need to either sort by descending (or ascending for some use case?) order. From what I read in the sort options, the default sort does not do what is needed for this issue.

@panda01
Copy link
Copy Markdown
Contributor

panda01 commented Jun 14, 2016

Do you want me to provide a combobox with, e.g., two options (desc and asc), so that the order option is not hardcoded ?

Exactly this! Maybe radio boxes though since i hate select boxes.

@scampi
Copy link
Copy Markdown
Contributor Author

scampi commented Jun 14, 2016

@panda01 I added a select box for choosing the order instead of radio boxes. I thought it was best to be consistent with the rest of kibana, e.g., the terms bucket aggregation uses a select box for the order. I can revert though.

In addition, the sort field is now by default the time field associated to the index pattern, as I had forgotten it mentioned in the issue.

@scampi
Copy link
Copy Markdown
Contributor Author

scampi commented Jun 15, 2016

@panda01 there is anyway another issue about the select box #2130 (comment) where the cool ui-select is mentioned ;o)

@panda01
Copy link
Copy Markdown
Contributor

panda01 commented Jun 21, 2016

@scampi in regards to using chosen, I would say the normal select box is appropriate for now. I will check out your changes.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this is a bit nitpicky of me, but I think the sort, and sort order should use the same property names, since they are dependent on one another, and I would hate for someone later to not realize that.

For instance you could call the sort field agg.params.sort.field and the order agg.params.sort.dir or something to that effect. but with that it's clear they're both dealing with the sort, no matter where it's put.

@scampi
Copy link
Copy Markdown
Contributor Author

scampi commented Dec 28, 2016

@Bargs I updated the aggregate menu. Regarding the sorting, I don't see what is wrong. Can you explain ? I tried to take the last/first value of a simple index and it was fine.

Copy link
Copy Markdown
Contributor

@Bargs Bargs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was having an issue where flipping between ascending and descending sort was giving me different values every time, as if the document was getting picked randomly. I see now that I accidentally screenshotted the response and not the request, so that's not helpful. Unfortunately I'm not sure what was happening and I can't reproduce it now. I'll let you know if I run into it again.

Otherwise, LGTM! All yours, @ppisljar

@ppisljar
Copy link
Copy Markdown
Contributor

ppisljar commented Dec 30, 2016

i am not sure whats happening ... i am using logstash data. if i do top hits on the bytes field (with default size of 1) it works ok ... if i try the same with memory fields it only returns - .. however if i increase size to lets say 2 then it works with the memory field as well ?

ibana20161230080423 1

@ppisljar
Copy link
Copy Markdown
Contributor

another visualization type was added (heatmap) ... could you also add the top hits there ... it should behave the same as with other xy charts (line,bar,area)

@ppisljar
Copy link
Copy Markdown
Contributor

This looks really good and its great to see all the way this came (it was marked as low fruit hehe :) ). Besides the two small things mentioned above i think this is good to go.

@ppisljar
Copy link
Copy Markdown
Contributor

try running npm run lintroller it seems to find two lets which should be consts (and auto updates them ... so you just need to commit after)

@scampi
Copy link
Copy Markdown
Contributor Author

scampi commented Jan 3, 2017

@ppisljar Regarding #7302 (comment) it seems that some documents don't have the memory field from what I saw locally. In your case, it would mean that the last before last has that field, but not the last one.

The last commits add the following:

  • added top hits metric to the heatmap.
  • fixed min/max of an array of values: it was returning infinity if all values were undefined/null.

Regarding that 2nd point, I would like to know if there is some default "zero" value. For example, if a field is missing:

  • if a string, then we'd return "N/A" or something set in the advanced settings
  • if a number, then we'd return "0" or "1" or something set in the advanced settings

The PR is now ready for review, but pending the answer to the previous question, some changes might be needed.

@ppisljar
Copy link
Copy Markdown
Contributor

ppisljar commented Jan 3, 2017

regarding second point it should probably behave the same as for non-array missing values ? @Bargs whats your opinion ?

@Bargs
Copy link
Copy Markdown
Contributor

Bargs commented Jan 3, 2017

Discover displays a - for any missing fields regardless of type, so I think we should do the same here to remain consistent.

@scampi
Copy link
Copy Markdown
Contributor Author

scampi commented Jan 3, 2017

ok then PR is ready ;o) I thought there was such a setting so I wanted to make sure

@ppisljar
Copy link
Copy Markdown
Contributor

ppisljar commented Jan 4, 2017

congrats scampi, this is a great PR and i am sure many are excited about finally having top hits in kibana!

@ppisljar
Copy link
Copy Markdown
Contributor

ppisljar commented Jan 4, 2017

the backport #9735 has some conflicts you'll need to resolve.

@Bargs
Copy link
Copy Markdown
Contributor

Bargs commented Jan 4, 2017

@scampi thanks for the great work on another giant PR! This is an awesome new metric, users are gonna love it.

@scampi
Copy link
Copy Markdown
Contributor Author

scampi commented Jan 5, 2017

Thanks @Bargs and @ppisljar for your help on this ;o)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature:Aggregations Aggregation infrastructure (AggConfig, esaggs, ...) Feature:Visualizations Generic visualization features (in case no more specific feature label is available) release_note:enhancement v5.3.0 v6.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"Latest" metric agg

8 participants